﻿using System.Data.SqlClient;

namespace PengSW.DbTools
{
    public static class SqlConnectionStringTools
    {
        public static string CreateSqlConnectionStringWithoutPassword(string aSqlConnectionString)
        {
            SqlConnectionStringBuilder aSqlConnectionStringBuilder = new SqlConnectionStringBuilder(aSqlConnectionString);
            aSqlConnectionStringBuilder.Password = "";
            return aSqlConnectionStringBuilder.ConnectionString;
        }

        public static string CreateEncrySqlConnectionString(string aPlaneSqlConnectionString, string aIV_64, string aKEY_64)
        {
            SqlConnectionStringBuilder aSqlConnectionStringBuilder = new SqlConnectionStringBuilder(aPlaneSqlConnectionString);
            if (aSqlConnectionStringBuilder.Password != string.Empty) aSqlConnectionStringBuilder.Password = PengSW.Crypt.Crypt.Encode(aSqlConnectionStringBuilder.Password, aKEY_64, aIV_64);
            return aSqlConnectionStringBuilder.ConnectionString;
        }

        public static string CreateDecrySqlConnectionString(string aEncrySqlConnectionString, string aIV_64, string aKEY_64)
        {
            SqlConnectionStringBuilder aSqlConnectionStringBuilder = new SqlConnectionStringBuilder(aEncrySqlConnectionString);
            if (aSqlConnectionStringBuilder.Password != string.Empty) aSqlConnectionStringBuilder.Password = PengSW.Crypt.Crypt.Decode(aSqlConnectionStringBuilder.Password, aKEY_64, aIV_64);
            return aSqlConnectionStringBuilder.ConnectionString;
        }
    }
}
